# -*- coding: utf-8 -*-
from jms.time_sensor import time_after_01_30
from utils.operators.latest_only_spark_submit_operator import LatestOnlySparkSubmitOperator
from utils.alerts.yl_threeSegCodeOnFailue import yl_threeSegCodeOnFailure
from utils.alerts.yl_threeSegCodeOnSuccess import yl_threeSegCodeOnSuccess
def kwargs():
    kwargs = {
        "db": "ai_dwd",
        "table": "yl_threesegcode_pdd_waybill_uat",
        "desc": "PDD流量运单uat数据",
        "taskid": "10180",
        "ifprivacy": 1,
        "warnignore": 0,
    }
    return kwargs


jms_ai_dwd__yl_threesegcode_pdd_waybill_uat = LatestOnlySparkSubmitOperator(
    task_id='jms_ai_dwd__yl_threesegcode_pdd_waybill_uat',
    pool_slots=4,
    # depends_on_past=True,  # 如果任务依赖于前一天的同名任务，则将 depends_on_past 设为 True
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_ai_dwd__yl_threesegcode_pdd_waybill_uat_{{ execution_date | date_add(1) | cst_ds }}',  # yarn 任务名称
    yarn_queue='pyspark',
    driver_memory='4G',
    email=['yushuo@jtexpress.com','yl_bigdata@yl-scm.com'],
    executor_memory='8G',
    executor_cores=5,
    num_executors=10,
    depends_on_past=True,
    conf={'spark.executor.memoryOverhead': 2048,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.default.parallelism': 600,
          'spark.locality.wait': 60,
          },
    java_class='com.jms.yl.ml.AIPddWaybillLogHDFS2HiveUat',  # spark 主类
    ##java_class='com.jms.yl.main.AIPddWaybillLogHDFS2Hive',  # spark 主类
    # application='hdfs:///user/spark/work/aigroup/yl_threesegcode_pdd_waybill/batch_process-1.0-SNAPSHOT-jar-with-dependencies.jar',
    application='hdfs:///scheduler/jms/spark/sj/yl_threesegcode_pdd_waybill/batch_process-1.0-SNAPSHOT-jar-with-dependencies.jar',
    # spark jar 包
    application_args=['{{ var.value.env | lower }}', '{{ execution_date | cst_ds }}'],  # 参数dt 2020-10-26
    on_success_callback=yl_threeSegCodeOnSuccess(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_info"),
    on_failure_callback=yl_threeSegCodeOnFailure(kwargs(), dingding_conn_id="dingding_ThreeSeg_etl_alert"),
)

# 设置依赖
jms_ai_dwd__yl_threesegcode_pdd_waybill_uat << [
    time_after_01_30]
